package com.example.ch3;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BeerSelect
 */
public class BeerSelect extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BeerSelect() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		PrintWriter out = response.getWriter();
		String colorSelected = request.getParameter("color");
		out.println("Hello " + request.getParameter("user") + ", you choose color " + colorSelected + ", and we suggest");
		List<String> brands = new BeerExpert().getBrands(colorSelected);
		Iterator<String> iterator = brands.iterator();
		while(iterator.hasNext()) {
			out.println("<br/>try: " + iterator.next());
		}
	}

}
